package com.pipayshop.controller;


import com.pipayshop.entity.BuyerData;
import com.pipayshop.entity.WithdrawalCommission;
import com.pipayshop.entity.vo.ResponseVO;
import com.pipayshop.exception.BusinessException;
import com.pipayshop.service.BuyerDataService;
import com.pipayshop.service.WithdrawalCommissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jnr.ffi.annotations.In;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 买家的收货地址（多选） 前端控制器
 * </p>
 *
 * @author nws
 * @since 2023-07-25
 */
@Api(value = "提现手续费接口",tags = "提现手续费接口")
@RestController
@RequestMapping("/pipayshopapi/withdrawal")
public class WithdrawalCommissionController {
    @Resource
    private WithdrawalCommissionService withdrawalCommissionService;

    @PostMapping("update")
    @ApiOperation("根据id修改手续费")
    public ResponseVO updateDefaultAddress(@RequestBody WithdrawalCommission withdrawalCommission){
        try {
            boolean result = withdrawalCommissionService.updateById(withdrawalCommission);
            return ResponseVO.getSuccessResponseVo(result);
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("Failed_to_modify_the_operation_fee");
        }
    }

    @GetMapping("selectAll")
    @ApiOperation("获取手续费信息")
    public ResponseVO<List<WithdrawalCommission>> selectAllAddress(){
        try {
            List<WithdrawalCommission> list = withdrawalCommissionService.selectAll();
            return ResponseVO.getSuccessResponseVo(list);
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("Failed_to_obtain_the_commission_information");
        }
    }

    @GetMapping("get/{id}")
    @ApiOperation("根据id查询手续费信息")
    public ResponseVO get(@PathVariable Integer id){
        try {
            WithdrawalCommission withdrawalCommission = withdrawalCommissionService.selectById(id);
            return ResponseVO.getSuccessResponseVo(withdrawalCommission);
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("Failed_to_query_the_specified_commission.");
        }
    }

    @PostMapping("insert")
    @ApiOperation("插入手续费信息")
    public ResponseVO insectBuyerData(@RequestBody WithdrawalCommission withdrawalCommission){
        try {
            boolean result = withdrawalCommissionService.insert(withdrawalCommission);
            if (!result){
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo("Add_fee_successfully");
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("Failed_to_add_commission");
        }
    }


    @PostMapping("deleteById/{id}")
    @ApiOperation("根据id删除手续费信息")
    public ResponseVO deleteBuyerDataById(@PathVariable Long id){
        try {
            boolean result = withdrawalCommissionService.deleteById(id);
            if (!result){
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo("Delete_handling_fee_successfully");
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("Failed_to_delete_handling_charge");
        }
    }

}
